# frozen_string_literal: true

require '../common/vagrant-common'

# Basic Vagrant config (API version 2)
Vagrant.configure(2) do |config|
  # Base box: Centos-7 box
  # NOTE: Over time the VMI below may become outdated, so may need to be
  #       substituted with a more recent VMI
  config.vm.box = 'bento/centos-7'

  # Make it so that network access from the vagrant guest is able to
  # use SSH private keys that are present on the host without copying
  # them into the VM.
  config.ssh.forward_agent = true

  config.vm.hostname = 'gpdbvagrant'

  # Give a reasonable amount of cpu and memory to the VM
  config.vm.provider :virtualbox do |vb|
    vb.memory = 8192
    vb.cpus = 4
    vb.customize [:storagectl,
                  :id,
                  '--name',
                  'SATA Controller',
                  '--hostiocache',
                  :on]
    vb.customize [:modifyvm, :id, '--cableconnected1', :on]
  end

  process_vagrant_local(config)

  config.vm.define(:gpdb) do |gpdb|
    name_vm config, 'gpdb-centos-dev-host'
    gpdb.vm.provision :shell, path: 'vagrant-setup.sh'
    gpdb.vm.provision :shell, path: 'vagrant-configure-os.sh'
    gpdb.vm.provision(:shell,
                      path: '../common/vagrant-build-gporca.sh',
                      privileged: false)
    gpdb.vm.provision(:shell,
                      path: '../common/vagrant-build-gpdb.sh',
                      privileged: false,
                      env: current_git_data,
                      args: gpdb_build_args)
  end

  config.vm.define(:gpdb_without_gporca) do |gpdb|
    name_vm config, 'gpdb-without-gporca-centos-dev-host'
    gpdb.vm.provision :shell, path: 'vagrant-setup.sh'
    gpdb.vm.provision :shell, path: 'vagrant-configure-os.sh'
    gpdb.vm.provision(:shell,
                      path: '../common/vagrant-build-gpdb.sh',
                      privileged: false,
                      env: current_git_data,
                      args: gpdb_build_args(with_gporca: false))
  end
end
